import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            name: 'home',
            component: () => import('@/views/home/index.vue')
        }
    ]
})
// 设置全局前置守卫
router.beforeEach(async (to, from, next) => {
    const isLoggedIn = await isUserLoggedIn()
    if (to.path == '/') { next() }
    if (localStorage.getItem('token') || !isLoggedIn) {
        next()
    }
    else {
        // next(false)
        next('/')
    }
});
function isUserLoggedIn() {
    // 这里可以是你检查用户登录状态的逻辑，返回一个Promise
    // 例如，可以通过调用API或检查localStorage/cookie来确定用户是否登录
    return new Promise((resolve) => {
        // if (localStorage.getItem('user')) {
        //     resolve(true) // 假设用户已经登录
        // }
        // 模拟异步检查逻辑
        setTimeout(() => {
            resolve(true) // 假设用户已经登录
        }, 500)
    })
}
// 导出
export default router